package cn.wit.db.config;

import javax.sql.DataSource;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;

@Configuration
@MapperScan("cn.wit.db.mapper")		// mapper包扫描
public class DaoConfigurer implements TransactionManagementConfigurer {
	// 配置数据源 datasource
	@Bean
	public DataSource configDataSource() {
		return DruidDataSourceBuilder.create().build();
	}
	
	@Bean
	public PlatformTransactionManager txManager() {
		return new DataSourceTransactionManager(configDataSource());
	}
	
	// 返回事务管理器
	@Override
	public PlatformTransactionManager annotationDrivenTransactionManager() {
		return txManager();
	}

}
